package com.aaa.security.utils;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author ：ludi（206913808@qq.com）
 * @date ：Created in 2022/12/2 23:40
 * @description：
 * @modified By：
 * @version:
 */
public class WebUtils {
    /**
     * @create by: ludi（206913808@qq.com）
     * @description: 获取request对象
     * @create time: 2022/12/2 23:49
     * @param
     * @return javax.servlet.http.HttpServletRequest
     */
    public static HttpServletRequest getRequest(){
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        if (requestAttributes == null){
            return null;
        }
        return ((ServletRequestAttributes)requestAttributes).getRequest();
    }


    /**
     * @create by: ludi（206913808@qq.com）
     * @description: 获取response对象
     * @create time: 2022/12/2 23:58
     * @param
     * @return HttpServletResponse
     */
    public static HttpServletResponse getResponse(){
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        if (requestAttributes == null){
            return null;
        }
        return ((ServletRequestAttributes)requestAttributes).getResponse();
    }
}